package com.example.demo.exchange.mq.ibmmq.receivelistener;


import javax.jms.Message;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.jms.core.JmsOperations;
import org.springframework.jms.listener.adapter.MessageListenerAdapter;
import org.springframework.stereotype.Component;

import com.example.demo.exchange.mq.MyMessage;
import com.example.demo.exchange.mq.ibmmq.factory.MessageFactory;
import com.example.demo.exchange.mq.ibmmq.mymessage.MessageOne;
 
@Component
public class ReceiveOneMessage extends MessageListenerAdapter{
	@Autowired
	JmsOperations jmsOperations;
 
    @Override
    @JmsListener(destination = "Q1")
    public void onMessage(Message message) {
        String messageBody = new String(message.toString());
        //TODO insert db?
        MyMessage msg = MessageFactory.create(messageBody, MessageOne.CODE);
        Boolean result = msg.send();
        //TODO add records?
    	//TODO logs
    }
}
